/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package bpmn.impl;

import bpmn.BpmnPackage;
import bpmn.Message;
import bpmn.Participant;
import bpmn.Property;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Message</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link bpmn.impl.MessageImpl#getName <em>Name</em>}</li>
 *   <li>{@link bpmn.impl.MessageImpl#getProperties <em>Properties</em>}</li>
 *   <li>{@link bpmn.impl.MessageImpl#getFromRef <em>From Ref</em>}</li>
 *   <li>{@link bpmn.impl.MessageImpl#getToRef <em>To Ref</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class MessageImpl extends SupportingElementImpl implements Message {
	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getProperties() <em>Properties</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getProperties()
	 * @generated
	 * @ordered
	 */
	protected Property properties;

	/**
	 * The cached value of the '{@link #getFromRef() <em>From Ref</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFromRef()
	 * @generated
	 * @ordered
	 */
	protected Participant fromRef;

	/**
	 * The cached value of the '{@link #getToRef() <em>To Ref</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getToRef()
	 * @generated
	 * @ordered
	 */
	protected Participant toRef;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected MessageImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return BpmnPackage.Literals.MESSAGE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.MESSAGE__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Property getProperties() {
		if (properties != null && properties.eIsProxy()) {
			InternalEObject oldProperties = (InternalEObject)properties;
			properties = (Property)eResolveProxy(oldProperties);
			if (properties != oldProperties) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, BpmnPackage.MESSAGE__PROPERTIES, oldProperties, properties));
			}
		}
		return properties;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Property basicGetProperties() {
		return properties;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setProperties(Property newProperties) {
		Property oldProperties = properties;
		properties = newProperties;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.MESSAGE__PROPERTIES, oldProperties, properties));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Participant getFromRef() {
		if (fromRef != null && fromRef.eIsProxy()) {
			InternalEObject oldFromRef = (InternalEObject)fromRef;
			fromRef = (Participant)eResolveProxy(oldFromRef);
			if (fromRef != oldFromRef) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, BpmnPackage.MESSAGE__FROM_REF, oldFromRef, fromRef));
			}
		}
		return fromRef;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Participant basicGetFromRef() {
		return fromRef;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setFromRef(Participant newFromRef) {
		Participant oldFromRef = fromRef;
		fromRef = newFromRef;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.MESSAGE__FROM_REF, oldFromRef, fromRef));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Participant getToRef() {
		if (toRef != null && toRef.eIsProxy()) {
			InternalEObject oldToRef = (InternalEObject)toRef;
			toRef = (Participant)eResolveProxy(oldToRef);
			if (toRef != oldToRef) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, BpmnPackage.MESSAGE__TO_REF, oldToRef, toRef));
			}
		}
		return toRef;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Participant basicGetToRef() {
		return toRef;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setToRef(Participant newToRef) {
		Participant oldToRef = toRef;
		toRef = newToRef;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.MESSAGE__TO_REF, oldToRef, toRef));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case BpmnPackage.MESSAGE__NAME:
				return getName();
			case BpmnPackage.MESSAGE__PROPERTIES:
				if (resolve) return getProperties();
				return basicGetProperties();
			case BpmnPackage.MESSAGE__FROM_REF:
				if (resolve) return getFromRef();
				return basicGetFromRef();
			case BpmnPackage.MESSAGE__TO_REF:
				if (resolve) return getToRef();
				return basicGetToRef();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case BpmnPackage.MESSAGE__NAME:
				setName((String)newValue);
				return;
			case BpmnPackage.MESSAGE__PROPERTIES:
				setProperties((Property)newValue);
				return;
			case BpmnPackage.MESSAGE__FROM_REF:
				setFromRef((Participant)newValue);
				return;
			case BpmnPackage.MESSAGE__TO_REF:
				setToRef((Participant)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case BpmnPackage.MESSAGE__NAME:
				setName(NAME_EDEFAULT);
				return;
			case BpmnPackage.MESSAGE__PROPERTIES:
				setProperties((Property)null);
				return;
			case BpmnPackage.MESSAGE__FROM_REF:
				setFromRef((Participant)null);
				return;
			case BpmnPackage.MESSAGE__TO_REF:
				setToRef((Participant)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case BpmnPackage.MESSAGE__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case BpmnPackage.MESSAGE__PROPERTIES:
				return properties != null;
			case BpmnPackage.MESSAGE__FROM_REF:
				return fromRef != null;
			case BpmnPackage.MESSAGE__TO_REF:
				return toRef != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (Name: ");
		result.append(name);
		result.append(')');
		return result.toString();
	}

} //MessageImpl
